package org.gd.hellojaxb.example.list;

import org.gd.hellojaxb.interfaces.XmlObject;
import org.gd.hellojaxb.utils.Marshall;
import org.gd.hellojaxb.utils.MarshallProperties;
import org.gd.hellojaxb.utils.Timer;

import java.util.ArrayList;
import java.util.List;

public class TestApp {

    public static void main(String[] args) {
        Timer.start();
        try {
            List<Book> bookList = new ArrayList<Book>();
            Author a = new Author();
            a.setName("author name");
            //a.setPlace("author place");


            Book book1 = new Book();
            book1.setIsbn("978-0060554736");
            book1.setName("The Game");
            book1.setAuthorName("Neil Strauss jr");
            book1.setPublisher("Harpercollins");
            book1.setAuthor(a);
            bookList.add(book1);

            book1.toXml();

            Book book2 = new Book();
            book2.setIsbn("978-3832180577");
            book2.setName("Feuchtgebiete");
            book2.setAuthorName("Charlotte Roche");
            book2.setPublisher("Dumont Buchverlag");
            bookList.add(book2);

            Book book3 = new Book();
            book3.setIsbn("978-3832180577");
            book3.setName("Feuchtgebiete");
            book3.setAuthorName("Charlotte Roche");
            book3.setPublisher("Dumont Buchverlag");
            bookList.add(book3);

            // create bookstore, assigning book
            Bookstore bookstore = new Bookstore();
            bookstore.setName("Fraport Bookstore");
            bookstore.setLocation("Frankfurt Airport");
            bookstore.setBookList(bookList);
            bookstore.setAuthor(new Author("name"));

            XmlObject XmlObject = bookstore;

            String xml = Marshall.getInstance().marshal(XmlObject, MarshallProperties.WITHOUT_XML_HEADER, MarshallProperties.FORMATTED_OUTPUT);

            System.out.println(xml);

            //bookstore.toXml();

            /*new Marshall(Bookstore.class, bookstore).setProperties(
                    //Marshaller.JAXB_FORMATTED_OUTPUT,
                    Marshaller.JAXB_FORMATTED_OUTPUT
            ).print(System.out);*/


            // Write to File
            //m.marshal(bookstore, new File(BOOKSTORE_XML));
            // get variables from our xml file, created before
            /*System.out.println();
            System.out.println("Output from our XML File: ");
            Unmarshaller um = context.createUnmarshaller();
            Bookstore bookstore2 = (Bookstore) um.unmarshal(new FileReader(BOOKSTORE_XML));
            ArrayList<Book> list = bookstore2.getBooksList();
            for (Book book : list) {
                System.out.println("Book: " + book.getName() + " from " + book.getAuthorName());
            }*/

            /*
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            String date = formatter.format(new Date());
            Calendar c = new GregorianCalendar();
            SimpleDateFormat formatter1 = new SimpleDateFormat("HH:mm:ss");
            c.setTime(formatter.parse(date));

            c.add(Calendar.DAY_OF_MONTH, 0);
            c.add(Calendar.HOUR_OF_DAY, 1);
            c.add(Calendar.MINUTE, 0);

            System.out.println(formatter1.format(new Date(c.getTime().getTime()-new Date().getTime())));
            */

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Timer.stop();
        }
    }
}
